<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of manipulasi
 *
 * @author Obi
 */
class M_katagori extends DataMapper {

    var $table = 'katagori';
    var $key = 'id';

    function __construct() {
        parent::__construct();
    }

    //put your code here
    function insert($form) {
        $this->db->insert($this->table, $form);
    }

    function update($form, $id) {
        $this->db->where($this->key, $id);
        $this->db->update($this->table, $form);
    }

    function delete($id) {
        $this->db->where($this->key, $id);
        $this->db->delete($this->table);
    }
	
	function select_data() {
		
        $sql = "select
                katagori.id,katagori.nama_katagori,katagori.kode_katagori,katagori.parentid,katagori2.nama_katagori as nama_parent_katagori
            from  
                katagori Left Join katagori katagori2 ON katagori.parentid=katagori2.id";

        $query = $this->db->query($sql);
        return $query->result();
    }
	
	function check_child($id = 0) {
		
        $sql = "select * 
					from katagori
				where parentid = $id";

        $query = $this->db->query($sql);
        return count($query->result());
    }

}

?>
